<?php
include 'DataBase.php';
class WordCreater{

	private $word;//用户的情绪
	private $img;//图片
	
	function __construct(){
		$this -> getInfo();
	}
	
		
	public function getWord(){
		return $this -> word;
	}
	
	public function getImg(){
		return $this -> img;
	}
	
	
	/**
	 * 获取数据库范围内的数字
	 * */
	private function randNum(){
		$sql = "SELECT COUNT(*) FROM game";
		$db = new DataBase();
		$rand = $db -> query($sql)[0][0];
		return mt_rand(1, $rand);
	}
	
	/*
	 *从数据库随机读取图片和内容 
	 */
	 
	private function getInfo(){
		$sql = "SELECT * FROM game WHERE id=" . $this -> randNum();
		$db = new DataBase();
		$result = $db -> query($sql);
		$this -> word = $result[0][1];
		$this -> img = $result[0][2];
	}

	/*

	* 消除图片
	
	*/
	public function  reverse2($s){
	    $len = mb_strlen($s, "utf-8");
	    $reverse = "";
	    for($i = 1; $i <= $len; $i++){
	        $reverse .=mb_substr($s, -($i), 1 , "utf-8");
	    }
	    return $reverse;
	}
}
?>